package com.element.security.server.service;

import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices;
import org.springframework.stereotype.Component;

/**
 * @auther WuJun.Zhang
 * @date 2022/2/18 下午9:02
 */
@Component
public class IAuthCodeInMemoryService extends InMemoryAuthorizationCodeServices {

    // 设置code码长度
    private RandomValueStringGenerator generator = new RandomValueStringGenerator(12);

    @Override
    public String createAuthorizationCode(OAuth2Authentication authentication) {
        String code = generator.generate();
        store(code, authentication);
        return code;
    }
}